package com.scisoft.scan.control.delivery;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import com.scisoft.scan.data.delivery.DeliveryOrderDetailBean;
import com.scisoft.scan.dy.R;
import com.scisoft.scan.util.CommonUtil;
import com.scisoft.scan.ws.WebServiceHelper_Delivery;

import java.util.List;

public class DeliveryOrderDetailActivity extends Activity {

    private ImageView iv_Back; //返回按钮
    private ListView lv_data;
    private List<DeliveryOrderDetailBean> deliveryOrderDetailBeanList;
    private String orderId;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//remove title bar  即隐藏标题栏
        setContentView(R.layout.activity_delivery_order_detail);

        //参数传递
        Intent intent = getIntent();
        //客户信息
        orderId = intent.getStringExtra("data");
        //控件初始化
        lv_data = findViewById(R.id.lv_data);
        //返回
        iv_Back = findViewById(R.id.iv_back);
        iv_Back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DeliveryOrderDetailActivity.this.finish();
            }
        });

        QueryData();
    }

    private void QueryData(){
        CommonUtil.showPress(DeliveryOrderDetailActivity.this);
        QueryDeliveryTask queryDeliveryTask = new QueryDeliveryTask(DeliveryOrderDetailActivity.this);
        queryDeliveryTask.execute();
    }
    //绑定数据
    private void  BindData(Context context) {
        //数据
        DeliveryOrderDetailAdapter adapter = new DeliveryOrderDetailAdapter(deliveryOrderDetailBeanList, context);
        lv_data.setAdapter(adapter);
    }
    //后台服务
    class QueryDeliveryTask extends AsyncTask<String, Integer, String> {
        private Context mcontext;
        private String msg = "";

        QueryDeliveryTask(Context context) {
            super();
            mcontext = context;
        }

        @Override
        protected String doInBackground(String... params) {
            //查询
            try {
                //查询列表数据
                deliveryOrderDetailBeanList = WebServiceHelper_Delivery.DELIVERY_13(orderId);
                msg = "成功";

            } catch (Exception e) {
                msg = e.getMessage();
                e.printStackTrace();
            }
            //将结果返回给onPostExecute方法
            return msg;
        }

        @Override
        //此方法可以在主线程改变UI
        protected void onPostExecute(String result) {
            CommonUtil.hidePress();
            if (msg.contains("成功")) {
                BindData(mcontext);
            } else {
                Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
            }
        }
    }

}
